#include <STC15F2K60S2.H>
#include "ADC.h"

#define FOSC    11059200L
#define BAUD    115200


unsigned char s;

void InitUart()
{
    SCON = 0x5a;             
    T2L = (65536 - (FOSC/4/BAUD));
    T2H = (65536 - (FOSC/4/BAUD)) >> 8;
    AUXR = 0x14;                
    AUXR |= 0x01;             
             
}


void SendData(unsigned char dat)
{
    while (!TI);                   
    TI = 0;                         
    s=SBUF = dat/11%20;                     
}


void LED(unsigned char x)
{
switch(x)	
		 {
			case 0:	P0=0xFF;break;
			case 1: P0=0xFF;break;
			case 2:	P0=0xFF;break;
			case 3:	P0=0xFF;break;
			case 4:	P0=0xFF;break;
			case 5:	P0=0x0F;break;
			case 6:	P0=0x0F;break;
			case 7:	P0=0x0F;break;
			case 8:	P0=0x0F;break;
			case 9:	P0=0x0F;break;
			case 10:	P0=0x0F;break;
			case 11:	P0=0x01;break;
			case 12:	P0=0x01;break;
			case 13:	P0=0x01;break;
			case 14:	P0=0x01;break;
			case 15:	P0=0x01;break;
			case 16:	P0=0x01;break;
			case 17:	P0=0x01;break;
			case 18:	P0=0x01;break;
      default:break;
		 }
}


void main()
{
    P0M0 = 0x01;
    P0M1 = 0x01;
    P1M0 = 0x00;
    P1M1 = 0x00;
  

    InitUart();                 
    InitADC(); 
    
    while (1)
    {
			
     
    SendData(1);
		                  
    SendData(GetADCResult(1));                
    Delay(40);
		LED(s);
    }
}